graph theory problems solved in python